package com.yazdankhah.beans;

import com.yazdankhah.utils.DataTools;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
import org.apache.log4j.Logger;

/**
 *
 * @author ahmad
 */
@ManagedBean(name = "bean")
@SessionScoped
public class Bean implements Serializable {
  
  private int chapter = 1;
  private int verse = 2;
  private int serial = 2;
  
  private Combo combo;
  private SubTrans transBean;
  private String subTranslationCombine;
  
  private static Logger logger = Logger.getLogger(Bean.class);
  
  

  public Bean() {
    
    combo = DataTools.lookupQuran(chapter, verse);
    
  } //constructor
  
  
  public String breakTranslations(AjaxBehaviorEvent event) {
    
    transBean = new SubTrans(combo.getCombination());
    subTranslationCombine = transBean.breakTranslations();
    
    //System.out.println("quranVerse = [" + quranVerse + "]");
    
    return null;
  } //method
  

  public String nextSubTranslations(AjaxBehaviorEvent event) {
    
    subTranslationCombine = transBean.nextCombinedTranslations();
    System.out.println("subTranslationCombine = [" + subTranslationCombine + "]");
    
    return null;
  } //method
  

  public String previousSubTranslations(AjaxBehaviorEvent event) {
    
    subTranslationCombine = transBean.previousCombinedTranslations();
    System.out.println("subTranslationCombine = [" + subTranslationCombine + "]");
    
    return null;
  } //method
  

  public String lookupVerse(AjaxBehaviorEvent event) {
    
    serial = DataTools.getSerial(chapter, verse);
    combo = DataTools.lookupQuran(serial);
    
    //System.out.println("quranVerse = [" + quranVerse + "]");
    
    return null;
  } //method


  public String lookupNextVerse(AjaxBehaviorEvent event) {
    
    serial++;
    VerseAddr verseAddr = DataTools.getVerseAddr(serial);
    combo = DataTools.lookupQuran(serial);
    
    chapter = verseAddr.getChapter();
    verse = verseAddr.getVerse();
    
    return null;
  } //method


  public String lookupPereviousVerse(AjaxBehaviorEvent event) {
    
    serial--;
    VerseAddr verseAddr = DataTools.getVerseAddr(serial);
    combo = DataTools.lookupQuran(serial);
    
    chapter = verseAddr.getChapter();
    verse = verseAddr.getVerse();
    
    return null;
  } //method


  public int getChapter() {
    return chapter;
  }


  public void setChapter(int chapter) {
    this.chapter = chapter;
  }


  public int getVerse() {
    return verse;
  }


  public void setVerse(int verse) {
    this.verse = verse;
  }


  public int getSerial() {
    return serial;
  }


  public void setSerial(int serial) {
    this.serial = serial;
  }


  public Combo getCombo() {
    return combo;
  }


  public void setCombo(Combo combo) {
    this.combo = combo;
  }


  public String getSubTranslationCombine() {
    return subTranslationCombine;
  }


  public void setSubTranslationCombine(String subTranslationCombine) {
    this.subTranslationCombine = subTranslationCombine;
  }


} //method
